package com.shuyan.base.algorithm;

public class MyThread extends Thread {

    private Object obj=new Object();
    private static int ticket = 10;

@Override
    public void run() {

        while (true) {
            synchronized(obj){
                if(ticket>0){
            try {
                Thread.sleep(200);
                System.out.println(Thread.currentThread().getName() + "--" + ticket--);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }}else{
                    break;
                }
        }
        }
    }

    public static void main(String[] args) {
        Thread t=new MyThread();
        t.start();
        new Thread(t).start();
        new Thread(t).start();
    }

}
